package ui;

import org.uqbar.arena.layout.HorizontalLayout;
import org.uqbar.arena.layout.VerticalLayout;
import org.uqbar.arena.widgets.Container;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.windows.WindowOwner;
import org.uqbar.arena.windows.Window;
import org.uqbar.arena.widgets.Button;
import org.uqbar.commons.utils.Home;
import org.uqbar.commons.utils.ApplicationContext;
import org.uqbar.arena.widgets.tables.Column;
import org.uqbar.arena.widgets.tables.Table;
import org.uqbar.arena.actions.MessageSend;

import Aplicacion.Captura;
import Homes.CapturasHome;

@SuppressWarnings("serial")
public class ConsultarPendientesWindow extends Window<Home<Captura>> {

	private Container mainPanel;

	public ConsultarPendientesWindow(WindowOwner parent) {
		super(parent, ApplicationContext.getInstance().getHome(Captura.class));
		this.setTitle("Foto Multas Application");
	}

	@Override
	public void createContents(Panel mainPanel) {
		this.mainPanel = mainPanel;
		mainPanel.setLayout(new VerticalLayout());
		this.createCapturasGrid();
		this.createButtons();
	} 
	
	private void createButtons() {
		Panel buttonPanel = new Panel(this.mainPanel).setLayout(new HorizontalLayout());
		new Button(buttonPanel)
			.setCaption("Ingresar Captura")
			.onClick(new MessageSend(this, "ingresarCaptura"));
		new Button(buttonPanel)
			.setCaption("Ingresar Patente Manualmente")
			.onClick(new MessageSend(this, "ingresarPatente"));
	}

	private void createCapturasGrid() {
		Table<Captura> table = new Table<Captura>(this.mainPanel, Captura.class);
		table.bindContentsToProperty(Home.OBJECTS);
		//table.bindSelection(IngresoCaptura.CAPTURA);

		new Column<Captura>(table)
			.setTitle("Infraccion")
			.setFixedSize(200)
			.bindContentsToProperty("infraccion");
		
		new Column<Captura>(table)
			.setTitle("Vehículo")
			.setFixedSize(200)
			.bindContentsToProperty("vehiculo");
	}
	
	public void ingresarCaptura() {
		new IngresarCapturaWindow(this, (CapturasHome)ApplicationContext.getInstance().getHome(Captura.class)).open();
	}
	
	public void ingresarPatente() {
		new IngresarPatenteWindow(this, (CapturasHome)ApplicationContext.getInstance().getHome(Captura.class)).open();
	}

}
